package org.nanotek;

import java.io.Serializable;

import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.MappedSuperclass;

/**
 * Can be used as a "default Super class" on case of 
 * a more refine and complex class hierarchy. 
 * 
 * @author josecanovamauger
 *
 * @param <T> Serializable Object that represents the ID (unique identifier) of 
 * any subclass. 
 * 
 */
@MappedSuperclass
@SuppressWarnings("serial")
public abstract class AbstractBase <T extends Serializable> implements Base<T>{

	@Id
	protected T id; 
	
	public AbstractBase(){ 
		id = null;
	}
	
	public AbstractBase(T id) {
		this.id = id;
	}

	public T getId() {
		return id;
	}

	public void setId(T id) {
		this.id = id;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((id == null) ? 0 : id.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		AbstractBase other = (AbstractBase) obj;
		if (id == null) {
			if (other.id != null)
				return false;
		} else if (!id.equals(other.id))
			return false;
		return true;
	}
	
	
}
